<template>
  <div class="head-box">
    <div class="headphoto-box" @click="toLoginRegister">
      <img :src="staticpath + header" v-if="header">
      <img v-else :src="headImg" />
    </div>
    <div class="nickname-box">{{nikeName}}</div>
    <div class="set-box" @click="toDetailedInfo" v-if="isShow">
      <van-icon name="setting-o" />
    </div>
  </div>
</template>

<script>
import defaultHead from "assets/img/headImg/defaultHead.jpg";
import { mapState } from "vuex";

export default {
  name:"headinfo",
  props: {
    nikeName: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      headImg: defaultHead,
      staticpath: localStorage.getItem("staticpath"),
    };
  },
  name: "",
  methods: {
    toDetailedInfo() {
      this.$router.push("/updatainfo");
    },
    toLoginRegister() {
      if(!this.userId){
        this.$router.push("/logorreg");
      } else {
        this.$router.push("/updatainfo");
      }
      
    },
  },
  computed: {
    ...mapState({
      header: (state) => state.moduleUser.header,
      userId: (state) => state.moduleUser.userId,
    }),
    isShow() {
      return this.userId;
    },
  },
};
</script>

<style scoped>
.head-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  height: 180px;
  background-color: #ff5456;
  margin-bottom: 15px;
  padding-top: 20px;
}
.headphoto-box {
  height: 69px;
  width: 69px;
  line-height: 64px;
  text-align: center;
  border-radius: 69px;
  background-color: #fff;
  margin-bottom: 10px;
  margin-top: 15px;
  overflow: hidden;
}
.headphoto-box img {
  height: 100%;
  width: 100%;
}
.nickname-box {
  color: #fff;
}
.set-box {
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 20px;
  color: #fff;
}
</style>